package com.example.springboot_mybatisplus.controller;

import com.example.springboot_mybatisplus.entity.User;
import com.example.springboot_mybatisplus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author linruhai
 * @date 2021/10/8 - 23:59
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @PostMapping("/insert")
    public int addUser(@RequestBody User user){
        return userService.add(user);
    }

    @GetMapping("/findAll")
    public List<User> findAll() {
        return userService.findAll();
    }

    @GetMapping("/findPage")
    public List<User> findPage(@RequestParam("page") Integer page,@RequestParam("pageSize") Integer pageSize) {
        return userService.findPage(page,pageSize);
    }

    @PostMapping("/update")
    public int updateUser(@RequestBody User user) {
        return userService.updateById(user);
    }

    @DeleteMapping("/delete")
    public int deleteUser( long id) {
        return userService.deleteById(id);
    }


}
